unit UFrmLogin;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, Animate, GIFCtrl, jpeg;

type
  TFrmLogin = class(TForm)
    Panel1: TPanel;
    Label2: TLabel;
    Label1: TLabel;
    btnAnterior: TSpeedButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label4: TLabel;
    SpeedButton1: TSpeedButton;
    Image1: TImage;
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnAnteriorClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton1Click(Sender: TObject);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmLogin: TFrmLogin;

implementation

uses
   modulo, principal;

{$R *.DFM}

procedure TFrmLogin.btnPrimeiroClick(Sender: TObject);
begin
   DMEscola.quser.close;
   DMEscola.quser.sql.clear;
   DMEscola.quser.SQL.add ('Select * From Usuario where usuario ='+char(39)+Edit1.text+char(39)+' and senha ='+char(39)+Edit2.text+char(39));
   DMEscola.quser.open;

   if  (DMEscola.quserUsuario.Value <> '') and (DMEscola.quserSenha.Value <> '') then
      Self.Close
   else
   begin
      ShowMessage('Usuario ou senha incorreta!+#13+Digite novamente');
      edit1.text := '';
      edit2.text := '';
      edit1.setfocus;
   end;

end;

procedure TFrmLogin.btnAnteriorClick(Sender: TObject);
begin
   Application.Terminate;
end;

procedure TFrmLogin.FormShow(Sender: TObject);
begin
   Edit1.Text := '';
   Edit2.Text := '';
end;

procedure TFrmLogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   Action := CaFree;
end;

procedure TFrmLogin.Button1Click(Sender: TObject);
begin
   DMEscola.quser.close;
   DMEscola.quser.sql.clear;
   DMEscola.quser.SQL.add ('Select * From Usuario where usuario ='+char(39)+Edit1.text+char(39)+' and senha ='+char(39)+Edit2.text+char(39));
   DMEscola.quser.open;

   if  (DMEscola.quserUsuario.Value <> '') and (DMEscola.quserSenha.Value <> '') then
      Self.Close
   else
   begin
      ShowMessage('Usuario ou senha incorreta!'+#13+'Digite novamente');
      edit1.text := '';
      edit2.text := '';
      edit1.setfocus;
   end;

end;

procedure TFrmLogin.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
    if Key = #13 then
    begin
      Key := #0;
      PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
    end;
end;

procedure TFrmLogin.SpeedButton1Click(Sender: TObject);
begin
   DMEscola.quser.close;
   DMEscola.quser.sql.clear;
   DMEscola.quser.SQL.add ('Select * From Usuario where usuario ='+char(39)+Edit1.text+char(39)+' and senha ='+char(39)+Edit2.text+char(39));
   DMEscola.quser.open;

   if  (DMEscola.quserUsuario.Value <> '') and (DMEscola.quserSenha.Value <> '') then
      Self.Close
   else
   begin
      ShowMessage('Usuario ou senha incorreta!'+#13+'Digite novamente');
      edit1.text := '';
      edit2.text := '';
      edit1.setfocus;
   end;
end;

procedure TFrmLogin.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
   if Key = #13 then
   begin
      DMEscola.quser.close;
      DMEscola.quser.sql.clear;
      DMEscola.quser.SQL.add ('Select * From Usuario where usuario ='+char(39)+Edit1.text+char(39)+' and senha ='+char(39)+Edit2.text+char(39));
      DMEscola.quser.open;
      if  (DMEscola.quserUsuario.Value <> '') and (DMEscola.quserSenha.Value <> '') then
         Self.Close
      else
      begin
         ShowMessage('Usuario ou senha incorreta!'+#13+'Digite novamente');
         edit1.text := '';
         edit2.text := '';
         edit1.setfocus;
      end;
   end;
end;

end.
